<?php
	
	namespace Aspic\UnitTest;
	
	use Aspic as A;

	abstract class AbstractUnitTest {
		
		protected $reflection;

		public function __construct() {
			$this->reflection = new \ReflectionClass($this);
		}
		
		/**
		 * Loop on $args and check for each param list (array) if the corresponding 
		 * $expected result match
		 * @param callable $callable The callable (method) to check
		 * @param array $argsList An 2 dimensions array that contains for each row a list of 
		 * param to pass to $callable
		 * @param type $expectedReturns For each $argsList[$i], the expected output of callable
		 * @return UnitTestResultCollection A collection of all the result of the check on 
		 * $callable
		 */
		protected function loopOnCallable(callable $callable, array $argsList, array $expectedReturns) {
			$utrCollection = new UnitTestResultCollection;
			
			foreach($argsList as $key => $args) {
				$result = call_user_func_array($callable, $args);
				
				$utr = new UnitTestResult;
				$utr->setTestedMethod($callable);
				
				if ($result == $expectedReturns[$key]) {
					$utr->setSuccessed(true);
				}
				else {
					$utr->setSuccessed(false);
				}
				
				$utrCollection->addItem($utr);
			}
			
			return $utrCollection;
		}
		
		/**
		 * Return true if the given $methodName should be treated as a unit test 
		 * method
		 */
		protected function isUnitTestMethodName($methodName) {
			return A\UString::endsWith($methodName, 'UnitTest');
		}
		
		/**
		 * 
		 * @return array An array containing ReflectionMethod objects
		 * @see isUnitTestMethodName
		 */
		protected function getUnitTestMethods() {
			$classMethods = $this->reflection->getMethods();
			$unitTestMethods = array();
			
			foreach($classMethods as $method) {
				$methodName = $method->getName();
				
				if ($this->isUnitTestMethodName($methodName)) {
					$unitTestMethods[] = $method;
				}
			}
			
			return $unitTestMethods;
		}
		
		public function run() {
			$unitTestMethods = $this->getUnitTestMethods();
			
			foreach ($unitTestMethods as $method) {
				
			}
		}
		
	}
	
?>